home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / faq / wdj0597.zip / SDKANN.ZIP / SOURCE.ZIP / ANN2HTML.C next >
C/C++ Source or Header  |  1996-06-02  |  4KB  |  170 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #ifndef TRUE
  6. #   define TRUE 1
  7. #endif
  8. #ifndef FALSE
  9. #   define FALSE 0
  10. #endif
  11.  
  12. const char* HtmlDir = "g:\\data\\web\\ron";
  13.  
  14. FILE* OpenHtml(int FileNum)
  15.     {
  16.     char    Path[512];
  17.     sprintf(Path, "%s\\sdk%05d.htm", FileNum);
  18.     FILE* Result = fopen(Path, "w");
  19.     if(!Result)
  20.         {
  21.         fprintf(stderr, "Could not open '%s' for writing.\n", Path);
  22.         exit(EXIT_FAILURE);
  23.         }
  24.  
  25.     return Result;
  26.     }
  27.  
  28. char   *Value(char*In)
  29.     {
  30.     while(*In && *In != ' ' && *In != '\t')
  31.         ++In;
  32.     while(*In && (*In == ' ' || *In == '\t'))
  33.         ++In;
  34.     return In;
  35.     }
  36.  
  37. void    OutputLine(FILE* Out, char *Line)
  38.     {
  39.     while(*Line)
  40.         {
  41.         if(*Line == '\"')
  42.             fprintf(Out, "\\042");
  43.         else if(*Line == '\\')
  44.             fprintf(Out, "\\\\");
  45.         else
  46.             fprintf(Out, "%c", *Line);
  47.         ++Line;
  48.         }
  49.     }
  50.  
  51. int GetLine(FILE* In, char*Out)
  52.     {
  53.     if(!fgets(Out, 127, In))
  54.         return FALSE;
  55.     else
  56.         {
  57.         int Len = strlen(Out);
  58.         if(Len > 0)
  59.             Out[Len-1]  = '\0';
  60.         return Len;
  61.         }
  62.     }
  63.  
  64.  
  65. void DoAnnotation(FILE* In, FILE* Out, char* Line, int Num)
  66.     {
  67.     int     NewLine;
  68.     char    Type[128];
  69.     char    Topic[128];
  70.     char    Keyword[128];
  71.     char   *Number = strchr(Line, '#');
  72.     GetLine(In, Type);
  73.     GetLine(In, Topic);
  74.     GetLine(In, Keyword);
  75.     if(!strcmpi(Value(Type), "Win3.1"))
  76.         strcpy(Type, "win31wh.hlp");
  77.     else if(!strcmpi(Value(Type), "Win16"))
  78.         strcpy(Type, "win31wh.hlp");
  79.     else if(!strncmp(Value(Type), "MFC", 3))
  80.         strcpy(Type, "mfc30.hlp");
  81.     else if(!strcmpi(Value(Type), "Win32"))
  82.         strcpy(Type, "win32.hlp");
  83.     else
  84.         printf("Bad type? : '%s'\n", Value(Type));
  85.     fprintf(Out, "%d\tRCDATA\nbegin\n", Num);
  86.     fprintf(Out, "\t\"%s\\0\"\n", Type);
  87.     fprintf(Out, "\t\"%s\t%s\\0\"\n", Number, Value(Topic));
  88.     fprintf(Out, "\t\"%s\\0\"\n", Value(Keyword));
  89.     fprintf(Out, "\t\"%s\\0\"\n", Value(Topic));
  90.     fprintf(Out, "\n");
  91.     fprintf(Out, "\"%s\"\n", Line);
  92.     NewLine = FALSE;
  93.     while(GetLine(In, Line))
  94.         {
  95.         int Len = strlen(Line);
  96.         if(!strncmp(Line, "--------", 8))
  97.             break;
  98.         if(Len == 0)
  99.             {
  100.             if(!NewLine)
  101.                 fprintf(Out, "\"\\r\\n\"\n");
  102.             fprintf(Out, "\"\\r\\n\"\n");
  103.             NewLine = TRUE;
  104.             }
  105.         else if(Len > 0)
  106.             {
  107.             if(Line[0] == ' ' || Line[0] == '\t')
  108.                 if(!NewLine)
  109.                     {
  110.                     NewLine     = TRUE;
  111.                     fprintf(Out, "\"\\r\\n\"\n");
  112.                     }
  113.             if(Line[Len-1] == '^' || Line[0] == ' ' || Line[0] == '\t')
  114.                 {
  115.                 if(Line[Len-1] == '^')
  116.                     Line[Len-1] = '\0';
  117.                 fprintf(Out, "\"");
  118.                 OutputLine(Out, Line);
  119.                 fprintf(Out, "\\r\\n\"\n", Line);
  120.                 NewLine = TRUE;
  121.                 }
  122.             else
  123.                 {
  124.                 fprintf(Out, "\"");
  125.                 OutputLine(Out, Line);
  126.                 fprintf(Out, " \"\n");
  127.                 NewLine = FALSE;
  128.                 }
  129.             }
  130.         }
  131.     fprintf(Out, "\"\\0\\0\\0\\0\"\nend\n\n");
  132.     }
  133.  
  134. void    Process(FILE *In, FILE *Out)
  135.     {
  136.     static char    Line[1024];
  137.     int Num = 0;
  138.     while(GetLine(In, Line))
  139.         {
  140.         if(!strncmp(Line, "WDJ SDK Annotation #", 20)
  141.         || !strncmp(Line, "WDJ MFC Annotation #", 20))
  142.             {
  143.             DoAnnotation(In, Out, Line, ++Num);
  144.             }
  145.         else if(!strncmp(Line, "WDJ ", 4))
  146.             printf("Bad line? : %s\n", Line);
  147.         }
  148.     printf( "Processed %d annotations\n", Num);
  149.     }
  150.  
  151.  
  152. void    main()
  153.     {
  154.     FILE *Fin   = fopen("..\\sdkann.txt", "r");
  155.     if(!Fin)
  156.         {
  157.         printf("Could not open '..\\sdkann.txt' for input\n");
  158.         exit(EXIT_FAILURE);
  159.         }
  160.     char    Path[512];
  161.     sprintf(Path, "%s\\sdkann.htm", FileNum);
  162.     FILE *Fout  = fopen(Path, "w");
  163.     if(!Fout)
  164.         {
  165.         printf("Could not open 'annotate.rc' for output\n");
  166.         exit(EXIT_FAILURE);
  167.         }
  168.     Process(Fin, Fout);
  169.     }
  170.